package org.example.erat.composite;

import org.example.erat.entity.ClassEntity;
import org.example.erat.entity.Course;
import org.example.erat.entity.Experiment;
import org.example.erat.entity.Student;
import org.example.erat.log.core.LoggerSingleton;

import java.util.List;
import java.util.Map;

/**
 * 统计组件抽象类
 * 实现组件接口的基本方法
 */
public abstract class AbstractStatisticsComponent implements StatisticsComponent {

    protected String name;

    public AbstractStatisticsComponent(String name) {
        this.name = name;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void addComponent(StatisticsComponent component) {
        throw new UnsupportedOperationException("叶子节点不支持添加子组件");
    }

    @Override
    public void removeComponent(StatisticsComponent component) {
        throw new UnsupportedOperationException("叶子节点不支持移除子组件");
    }

    @Override
    public StatisticsComponent getComponent(String name) {
        throw new UnsupportedOperationException("叶子节点不支持获取子组件");
    }

    @Override
    public Map<String, Object> execute(ClassEntity classEntity, Course course,
                                     List<Student> students, List<Experiment> experiments,
                                     Map<String, Object> reportData) {
        LoggerSingleton.getInstance().info("执行统计组件: {}", getName());
        return doExecute(classEntity, course, students, experiments, reportData);
    }

    /**
     * 执行具体的统计逻辑
     * @param classEntity 班级
     * @param course 课程
     * @param students 学生列表
     * @param experiments 实验列表
     * @param reportData 报告数据
     * @return 统计结果
     */
    protected abstract Map<String, Object> doExecute(ClassEntity classEntity, Course course,
                                                  List<Student> students, List<Experiment> experiments,
                                                  Map<String, Object> reportData);
}
